package com.example.test2.activity;

import android.os.Bundle;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewbinding.ViewBinding;

import com.example.test2.R;
import com.example.test2.utils.Tools;

// TODO: 2024/5/29 基类
public abstract class BaseActivity<T extends ViewBinding> extends AppCompatActivity {

    private T mBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initStatusBar();
        mBinding = onCreateViewBinding(getLayoutInflater());
        setContentView(mBinding.getRoot());
        initData();
        initClick();
    }

    protected void initStatusBar() {
        Tools.setStatusBarColor(this, R.color.bg_title);
    }

    protected void initData() {

    }

    protected void initClick() {

    }

    protected abstract int initLayout();//避免布局文件被删掉

    protected abstract T onCreateViewBinding(@NonNull LayoutInflater layoutInflater);

    public T getBinding() {
        return mBinding;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mBinding=null;
    }
}



